package com.chendx.store.seckill.controller;

import com.chendx.model.common.dtos.ResponseResult;
import com.chendx.model.common.enums.AppHttpCodeEnum;
import com.chendx.model.seckill.dto.SeckillGoodsDto;
import com.chendx.store.api.seckill.SeckillGoodsControllerApi;
import com.chendx.store.common.entity.DateUtil;
import com.chendx.store.seckill.service.SeckillGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

/**
 * Created by chendx on 2022/4/22.
 */
@RestController
@RequestMapping("/api/goods")
public class SeckillGoodsController implements SeckillGoodsControllerApi{


    @Autowired
    private SeckillGoodsService seckillGoodsService;

    @Override
    @GetMapping("/menus")
    public ResponseResult menus() {
        try {
            List<Date> dateMenus = DateUtil.getDateMenus();
            return ResponseResult.okResult(dateMenus);
        } catch (ParseException e) {
            e.printStackTrace();
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
        }
    }

    @Override
    @GetMapping("/load")
    public ResponseResult load(String time) {
        return seckillGoodsService.load(time);
    }

    @Override
    @GetMapping("/loadSeckillGoods")
    public ResponseResult loadSeckillGoods() {
        return seckillGoodsService.loadSeckillGoods();
    }

    @Override
    @PostMapping("/one")
    public ResponseResult loadOne(@RequestBody SeckillGoodsDto dto) {
        return seckillGoodsService.loadOne(dto);
    }

}
